var form,$,table,layer,upload,node;
var user = JSON.parse(localStorage.getItem("user"));
var userId = user.userId;
layui.use(['form','jquery','table','layer','upload'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    upload = layui.upload;

    //获取商品数目
    getProductNums();
    //获取商品列表数据
    getProductList('','','','');
});

$(".btn").on("click","button",function () {
    $(this).removeClass("layui-btn-primary").siblings("button").addClass("layui-btn-primary");
});
$(".btn").on("mouseover","button",function () {
    $(this).css("border-color","#d2d2d2");
});

//获取商品数目
function getProductNums(){
    $.ajax({
        url:'/toExamine/getProductNums',
        type: "post",
        dataType:'json',
        data: {},
        success:function (data) {
            $("#allProductNums").text(data.data.allMicrocircleNums);
            $("#productAdoptNums").text(data.data.microcircleAdoptNums);
            $("#productWaitNums").text(data.data.microcircleWaitNums);
            $("#productNoAdoptNums").text(data.data.microcircleNoAdoptNums);
        }
    });
}
////获取商品列表信息
function getProductList(result, title, productName, createName){
    $.ajax({
        url:'/toExamine/getAllProduct',
        type: "post",
        dataType:'json',
        data: {
            "result": result,
            "title": title,
            "productName": productName,
            "createName": createName,
        },
        success:function (data) {
            //展示table表格
            showMicrocircleList(data.data);
        }
    });
}

function showMicrocircleList(data) {
    table.render({
        elem: "#demo",
        data: data,
        toolbar:'#toolutil',
        page: true,
        limit: 10,
        cols:[[
            {title:'序号', align:'center',unresize:true, templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'productCode',title:'商品编号',unresize:true, align:'center'},
            {field:'mainImage',title:'商品图片',align:'center',unresize:true, templet:function(data){
                    return "<img src=' " + data.mainImage  + " '>";
                }},
            {field:'productName',title:'商品名称',align:'center',unresize:true},
            {field:'currentpriceProduct',title:'价格',align:'center',unresize:true},
            {field:'title',title:'分类',align:'center',unresize:true},
            {field:'createName',title:'上传人员',align:'center',unresize:true},
            {field:'result',title:'审核状态',align:'center',unresize:true, templet:function (data) {
                    if (data.result == 1){
                        return '审核通过';
                    }else if (data.result == 2){
                        return '待审核';
                    }else if (data.result == 3) {
                        return '审核驳回';
                    }
                }},
            {title:'操作',align:'center',unresize:true, templet:function(data){
                    if (data.result == 1){
                        return "<a href='JavaScript:selectProduct(\"" + data.productId +  "\");' class='operation'>查看</a>";
                    } else if (data.result == 2){
                        return "<a href='JavaScript:selectProduct(\"" + data.productId +  "\");' class='operation'>查看</a>" + '&nbsp;&nbsp;'
                            +"<a class='operation' href='javascript:judge(\"" + data.toExamineId + "\", \"" + data.productName + "\", \"" + data.productId + "\");'>审核</a>";
                    } else if (data.result == 3) {
                        return "<a href='JavaScript:selectProduct(\"" + data.productId +  "\");' class='operation'>查看</a>";
                    }
                }},
        ]]
    });
}

//查看商品审核
function  selectProduct(productId) {
    $('#proId').val(productId);
    layer.open({
        type: 2,
        content: "/toexamine/productlist-layer/productlist-search.html",
        area: ['1100px','500px'],
        end: function () {

        }
    });
}

//审核
function judge(id, productName, productId){
    $('#proId').val(id);
    $('#proName').val(productName);
    $('#productId').val(productId);
    layer.open({
        type:2,
        area:['540px','350px'],
        content:"/toexamine/productlist-layer/toExamine.html",
    });
}

//搜索
$("#selMicroCircle").on("click",function () {
    var title = $("input[name=title]").val();
    var productName = $("input[name=productName]").val();
    var createName = $("input[name=createName]").val();
    getProductList('',title,productName,createName);
});

//高级搜索
function accurate() {
    layer.open({
        type:2,
        content:"/toexamine/productlist-layer/productlist-seniorsearch.html",
        area:['490px','500px'],
        end:function () {

        }
    })
}
//刷新
function refresh() {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}